package com.kgd.news.wxpay.controller;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;
import com.kgd.news.entity.Order;
import com.kgd.news.utils.ApiController;
import com.kgd.news.wxpay.util.OrderUtils;

import java.sql.SQLException;
import java.util.List;

public class WxPayController extends ApiController {

    public void testQueryOrder() {
        String out_trade_no = getPara("out_trade_no");
        Order order = Order.dao.findFirst("select * from  `order` where orderid ='" + out_trade_no + "'");
        OrderUtils.checkOrderAndCash(order,10);
    }

    public void testTransaction() {
//        测试如果返回false，或者出错了，会回滚的
        Db.tx(new IAtom() {
            @Override
            public boolean run() throws SQLException {
                List<Order> orderList = Order.dao.find("select * from `order`");
                for (Order order : orderList
                        ) {
                    order.setState(3);
                    order.update();
                }
                return true;
            }
        });
    }
}
